#include "mcard.h"
#include <exception>

MCard::MCard()
{
    id = -1;
}

bool MCard::operator<(const MCard &a) const
{
    return id < a.id;
}

QString MCard::str() const
{
    switch (id) {
    case 7:
        return "10";
    case 8:
        return "J";
    case 9:
        return "Q";
    case 10:
        return "K";
    case 11:
        return "A";
    case 12:
        return "2";
    case 13:
        return "jk";
    case 14:
        return "JK";
    case -1:
        return "";
    default:
        return QString('3' + id);
    }
}

void MCard::setByStr(const QString s)
{
    QString t = s.toUpper();
    id = -1;
    if (s == "jk")
        id = 13;
    else if (s == "JK")
        id = 14;
    if (t == "3")   id = 0;
    if (t == "4")   id = 1;
    if (t == "5")   id = 2;
    if (t == "6")   id = 3;
    if (t == "7")   id = 4;
    if (t == "8")   id = 5;
    if (t == "9")   id = 6;
    if (t == "10")  id = 7;
    if (t == "J")   id = 8;
    if (t == "Q")   id = 9;
    if (t == "K")   id = 10;
    if (t == "A")   id = 11;
    if (t == "2")   id = 12;
}

MCard MCard::fromStr(const QString s)
{
    MCard a;
    a.setByStr(s);
    return a;
}
